const Token = require("../common/jwt");
const { Controller, POST } = require("../common/decorator/http");
const { jsonToString } = require("../common/serialize");

@Controller("/user")
class LoginController {
    @POST("/login/:username")
    async login(ctx, next) {
        try {
            const { username } = ctx.params;
            if (username) {
                ctx.body = {
                    code: '',
                    token: Token.encrypt(username)
                };
            }
        } catch (error) {
            ctx.status = 500;
            ctx.body = {
                error: error.message
            };
        } finally {
            next();
        }
    }
}

module.exports = LoginController;